import fs from 'fs';
import http from 'http';

let port=3000;

let abc=http.createServer((req,res)=>{
    let apath=req.url;
    let tpath="."+apath+'/'+'index.html';
    console.log(tpath);
    fs.readFile(tpath,'utf-8',(err,data)=>{
        if(err){
            res.setHeader('content-type','text/html;charset=utf-8');
            console.log(err);
            res.end("无此页面");
        }else{
            res.writeHead(200,'{content-type:text/html;charset=utf-8}');
            res.end(data);
        }
    });
});

abc.listen(port,()=>{
    console.log("监听成功");
})

console.log(`服务器运行于http://localhost:${port}`);